package svc

import (
	"MBTI/common"
	"MBTI/model"
	"MBTI/rpc/login/internal/config"
	"fmt"
)

type ServiceContext struct {
	Config       config.Config
	StudentModel model.StudentModel
}

func NewServiceContext(c config.Config) *ServiceContext {
	psqlcfg := c.Postgresql
	dsn := fmt.Sprintf("user=%s password=%s dbname=%s host=%s port=%d sslmode=disable TimeZone=Asia/Shanghai",
		psqlcfg.User,
		psqlcfg.Password,
		psqlcfg.Name,
		psqlcfg.Host,
		psqlcfg.Port,
	)
	conn := common.NewPostgresqlGorm(dsn)

	return &ServiceContext{
		Config:       c,
		StudentModel: model.NewStudentModel(conn),
	}
}
